let dbConfig = {}

if (process.env.MYSQL_DATABASE) {
	console.log('dbConfig of env')
	dbConfig = {
		database: process.env.MYSQL_DATABASE,
		port: process.env.MYSQL_PORT || 3306,
        timezone: "UTC+8",
		replication: {
			read: [{
				host: process.env.MYSQL_READ_HOST,
				username: process.env.MYSQL_READ_USERNAME,
				password: process.env.MYSQL_READ_PASSWORD
			}],
			write: {
				host: process.env.MYSQL_WRITE_HOST,
				username: process.env.MYSQL_WRITE_USERNAME,
				password: process.env.MYSQL_WRITE_PASSWORD
			}
		},
		pool: {
			maxConnections: process.env.MYSQL_MAXCONNECTIONS || 20,
			maxIdleTime: process.env.MYSQL_MAXIDLETIME || 30000 
		}
	}
}else {
	console.log('db config file')
	dbConfig = require('./db.json')
}

module.exports = dbConfig
